package com.tbit.uqbike.client.pojo.dto;

import com.tbit.common.constant.RideLogDetailsConstant;
import com.tbit.uqbike.client.constant.CardTypeConstant;
import com.tbit.uqbike.client.pojo.RideLogDetails;
import lombok.Data;

import java.util.Date;
import java.util.Objects;

/**
 * 未支付订单使用卡券信息
 *
 * @author <a href="mailto:chen.wutian@tbit.com.cn">BUGTian</a>
 * @since 2025/5/21
 */
@Data
public class UnpaidOrderUseCarDTO {

    /**
     * 骑行卡id
     */
    private Integer rideCardId;

    /**
     * vip卡id
     */
    private Integer vipId;

    /**
     * 用户优惠券id
     */
    private Integer couponuserId;


    /**
     * 获取使用卡券后的订单备注
     * @param money 可抵扣金额
     * @param rideLogDetails 骑行订单详情
     * @param now 当前时间
     * @param deductionCardType 抵扣的卡券类型
     */
    public void setBillingDetails(Long money, RideLogDetails rideLogDetails, Date now, Integer deductionCardType) {
        String type;
        switch (deductionCardType) {
            case CardTypeConstant.TYPE_RIDECARD:
                type = "%s,用户使用骑行卡抵扣:%s元";
                rideLogDetails.setRideCard(money);
                break;
            case CardTypeConstant.TYPE_VIP:
                type = "%s,用户使用会员卡抵扣:%s元";
                rideLogDetails.setVipCard(money);
                break;
            case CardTypeConstant.TYPE_MEAL:
                type = "%s,用户使用优惠券抵扣:%s元";
                rideLogDetails.setCouponCard(money);
                break;
            default:
                type = "未知卡券类型";
                break;
        }
        //抵扣全部费用
        if (Objects.equals(rideLogDetails.getDeductionEndMoney(), money)) {
            rideLogDetails.setPayTime(now);
            rideLogDetails.setPayStatus(RideLogDetailsConstant.ORDER_PAY);
        }
        rideLogDetails.setBillingDetails(String.format(type, rideLogDetails.getBillingDetails(), money / 100));
    }
}
